﻿using System;
using System.Xml;
using System.Collections;
using Notepad_X.Components;

namespace Notepad_X.Classes
{
    public enum Icons {none,file,@new,open,recent,clear,save,saveas,close,remove,cancel,print,printpreview,pagesetup,exit,edit,undo,redo,copy,cut,paste,find,@goto,next,tabs,rename,tools,options,highlight,favourites,linenumbers,help,about,website,bugreport,submitanidea,shortcut,plugins,toolbar,download,documentok,documentchanged,refresh,update,ok,apply,previous,icons,add,replace};
   
    public class Settings
    {
        #region Variables

        /// <summary>
        /// Main Window Size
        /// </summary>
        public int[] size;
        /// <summary>
        /// Main Window Location
        /// </summary>
        public int[] location;
        /// <summary>
        /// Application language english is the default, else the file name of the translation
        /// </summary>
        public string language;
        /// <summary>
        /// Text font 
        /// </summary>
        public System.Drawing.Font font;
        /// <summary>
        /// List with all the extensions filter at save dialog
        /// </summary>
        public string extension_save;
        /// <summary>
        /// List with all the extensions filter at open dialog
        /// </summary>
        public string extension_open;
        /// <summary>
        /// Icons null value if there no icons else the file name
        /// </summary>
        public string icons;
        /// <summary>
        /// Show the line numbers
        /// </summary>
        public bool line_numbers;
        /// <summary>
        /// Show the status bar
        /// </summary>
        public bool status_bar;
        /// <summary>
        /// Background Color (if null it's default)
        /// </summary>
        public string BackgroundColor;
        /// <summary>
        /// Text Color (if null it's default)
        /// </summary>
        public string TextColor;
        /// <summary>
        /// Is it Lite version
        /// </summary>
        public bool LiteVersion;
        /// <summary>
        /// List with the favourite files
        /// </summary>
        public System.Collections.Generic.List<RecentMenuItemX> favourites;
        /// <summary>
        /// List with the toolbars
        /// </summary>
        public System.Collections.Generic.List<Toolbar> toolbars;//public System.Collections.Hashtable toolbars;
        /// <summary>
        /// List with the keyboard shortcuts for the application
        /// </summary>
        public System.Collections.Hashtable shortcuts;
        /// <summary>
        /// Control list with the recent files
        /// </summary>
        public Notepad_X.Components.RecentMenuItemX[] recent;

        public System.Collections.Generic.List<pluginSetting> pluginsSettings;

        public int defaultDocumentType;
        #endregion

        /// <summary>
        /// Favourites Menu
        /// </summary>
        System.Windows.Forms.ToolStripMenuItem menu;
        /// <summary>
        /// Main menu instance
        /// </summary>
        Main main;

        public Settings()
        {
            main = Static.MainInstance;
        }
        public void setFavouritesMenu(System.Windows.Forms.ToolStripMenuItem _menu)
        {
           menu = _menu;
        }

        /// <summary>
        /// Set the default settings
        /// </summary>
        public void set_default()
        {
            size = new int[]{500,200};
            location = new int[] { 200, 200 };
            language = "english";
            font = new System.Drawing.Font("Arial",10,System.Drawing.FontStyle.Regular); 
            extension_save = "Text Documents|*.txt|HTML Document|*.html|PHP Documents|*.php|All Files|*.*";
            extension_open = "All Files|*.*|Settings Files|*.txt;*.ini;*.reg|Programmng Files| *.vb;*.vbs;*.as;*.js;*.cs;*.c;*.cpp;*.java;*.pl|Web Files|*.htm;*.html;*.css;*.js;*.xml;*.vbs;*.asp;*.php";
            icons = "default.xml";
            line_numbers = false;
            status_bar = true;
            BackgroundColor = null;
            TextColor = null;
            LiteVersion = false;
            favourites = new System.Collections.Generic.List<RecentMenuItemX>();
            toolbars = new System.Collections.Generic.List<Toolbar>();

            shortcuts = new Hashtable(); // Add default shortcuts
            
            shortcut_add("Menu_File_New","control|N");
            shortcut_add("Menu_File_Open","control|O");
            shortcut_add("Menu_File_Save","control|S");
            shortcut_add("Menu_File_SaveAs","control|shift|C");
            shortcut_add("Menu_File_Print","control|P");
            shortcut_add("Menu_File_Exit","alt|F4");
            shortcut_add("Menu_Edit_Copy","control|C");
            shortcut_add("Menu_Edit_Cut","control|X");
            shortcut_add("Menu_Edit_Paste","control|P");
            shortcut_add("Menu_Edit_Redo","control|Y");
            shortcut_add("Menu_Edit_Undo","control|Z");
            shortcut_add("Menu_Edit_Find","control|F");
            shortcut_add("Menu_Edit_SelectAll","control|A");
            shortcut_add("Tabs_Select_0","control|D1");
            shortcut_add("Tabs_Select_1","control|D2");
            shortcut_add("Tabs_Select_2","control|D3");
            shortcut_add("Tabs_Select_3","control|D4");
            shortcut_add("Tabs_Select_4","control|D5");
            shortcut_add("Tabs_Select_5","control|D6");
            shortcut_add("Tabs_Select_6","control|D7");
            shortcut_add("Tabs_Select_7","control|D8");
            shortcut_add("Tabs_Select_8","control|D9");
            shortcut_add("Tabs_Select_9","control|D0");
            shortcut_add("Menu_Tabs_Close","control|W");
            shortcut_add("Menu_Tabs_New", "control|T");

            //Create the recent menu item
            recent = new RecentMenuItemX[7];

            defaultDocumentType=0;

            for (int i = 0; i < recent.Length; i++)
            {
                recent[i] = new RecentMenuItemX();
                recent[i].Visible = false;
            }

            pluginsSettings = new System.Collections.Generic.List<pluginSetting>();
        }
        public void addControls(System.Windows.Forms.ToolStripMenuItem menu)//Recent
        {
            menu.DropDownItems.AddRange(recent);
        }

        // 
        /// <summary>
        /// Reades an icon file and stores the icon key the the icon as bitmap
        /// </summary>
        /// <param name="value">Iconpack name</param>
        public void iconReader(string value)
        {
            icons = value;
            if (icons == "default")
            {
                //changes will take effect after restart
            }
            else
            {
                if (System.IO.File.Exists(Main.System_ROOT + "\\Icons\\" + icons))
                {
                    String[] Hash = hashIconPack(Main.System_ROOT + "\\Icons\\" + icons);
                    if (Hash != null)
                    {
                        XmlDocument xmlFile = new XmlDocument();
                        xmlFile.Load(Main.System_ROOT + "\\Icons\\" + icons);

                        XmlNodeList nodes = xmlFile.GetElementsByTagName("Information");

                  
                            String ImageFolder = Main.System_ROOT + "\\Icons\\" + Hash[0] + "\\";
                            foreach (XmlNode node in xmlFile.SelectNodes("NotepadX/Icon"))
                            {
                                string key = node.Attributes.GetNamedItem("Key").InnerText.ToLower();
                                string file = node.Attributes.GetNamedItem("File").InnerText;
                                if (System.IO.File.Exists(ImageFolder + file))
                                {
                                    //Update the icon if already exists
                                    if (main.IconsCollection.Images.ContainsKey(key))
                                    {
                                        main.IconsCollection.Images.RemoveByKey(key);
                                    }

                                    System.Drawing.Bitmap NewIcon = new System.Drawing.Bitmap(ImageFolder + file);

                                    main.IconsCollection.Images.Add(key, NewIcon);
                                }

                            }                    
                    }else{
                        icons = "default";
                    }
                }else{
                    icons = "default";
                }
            }
        }
        /// <summary>
        /// Clear all recent files
        /// </summary>
        public void recent_clear()
        {
            for (int i = 0; i < recent.Length; i++)
            {
                recent[i].changePath(null);
                recent[i].Visible = false;
            }
        }
        /// <summary>
        /// Add file to the recents
        /// </summary>
        /// <param name="path">the file path</param>
        public void recent_add(string path) // Add file to recents
        {
            if (recent[0].path == path)
            {
                //do nothing
            }
            else
            {
                int found = (recent.Length - 1);
                int i;
                for (i = 0; i < recent.Length; i++)
                {
                    if (recent[i].path == path)
                    {
                        found = i;
                    }
                }

                for (i = found; i > 0; i--)
                {
                    if (recent[i - 1] != null)
                    {
                        recent[i].changePath(recent[i - 1].path);
                    }
                }
                recent[0].changePath(path);
            }
        }
        /// <summary>
        /// Add shortcut 
        /// </summary>
        /// <param name="name">Control name</param>
        /// <param name="shortcut">Shortcut</param>
        public void shortcut_add(string name, string shortcut) 
        {
            System.Windows.Forms.ToolStripMenuItem item = main.system_menuItem_Get(name);
            if (item != null)
            {
                string[] parser = shortcut.ToLower().Split('|');
                bool _control = false;
                bool _shift = false;
                bool _alt = false;
                System.Windows.Forms.Keys _key;
                for (int i = 0; i < parser.Length - 1; i++)
                {
                    switch (parser[i])
                    {
                        case "control":
                            _control = true;
                            break;
                        case "shift":
                            _shift = true;
                            break;
                        case "alt":
                            _alt = true;
                            break;
                    }
                }

                System.Windows.Forms.KeysConverter _converter = new System.Windows.Forms.KeysConverter();
                string str = parser[parser.Length - 1].ToUpper();
                if (str.Length > 1)
                {
                    str = str.Substring(0, 1).ToUpper() + str.Substring(1, str.Length - 1).ToLower();
                }
                _key = (System.Windows.Forms.Keys)_converter.ConvertFromString(str);

                if (shortcuts.ContainsKey(name.ToLower()))
                {
                    shortcutkey newKey = new shortcutkey(_control, _shift, _alt, _key);
                    shortcuts[name.ToLower()] = new shortcut(item,newKey.key,newKey.getString);
                }
                else
                {
                    shortcutkey newKey = new shortcutkey(_control, _shift, _alt, _key);
                    shortcuts.Add(name.ToLower(),new shortcut(item,newKey.key,newKey.getString));
                }
            }
        }

        /// <summary>
        /// Add file to favourites
        /// </summary>
        /// <param name="path">file path</param>
        /// <returns>if file already exists at the list</returns>
        public bool favourite_add(string path)
        {
            bool found = false;
            for (int i = 0; i < favourites.Count; i++)
            {
                if (favourites[i].GetType() == typeof(RecentMenuItemX))
                {
                    if (favourites[i].path == path)
                    {
                        found = true;
                    }
                }
            }

            if (found)
            {
                return false;
            }else{
                RecentMenuItemX newItem = new RecentMenuItemX();
                newItem.changePath(path);   
                newItem.Click += new System.EventHandler(main.handler_openRecent);
                favourites.Add(newItem);
                menu.DropDownItems.Add(favourites[favourites.Count - 1]);
                return true;
            }
            
        }
        /// <summary>
        /// Adds a toolbar to the toolbar Collection
        /// </summary>
        /// <param name="filename">The toolbar filename</param>
        public int toolbar_add(string filename)
        {
             if (System.IO.File.Exists(Main.System_ROOT + "\\toolbars\\" + filename))
             {          
                Toolbar newToolbar = new Toolbar();
                newToolbar.Create(Main.System_ROOT + "\\toolbars\\" + filename);
                main.Controls.Add(newToolbar.nToolbar);
                newToolbar.DisplayIndex = toolbars.Count;
                 toolbars.Add(newToolbar);
                 return toolbars.Count - 1;
             }
             return -1;
        }
        /// <summary>
        /// Checks if a toolbar exists at the toolbar collection
        /// </summary>
        /// <param name="name">Toolbar name</param>
        public bool toolbar_exist(string name)
        {
            name = name.ToLower();
            foreach (Toolbar toolbar in toolbars)
            {
                if (toolbar.Name.ToLower() == name)
                {
                    return true;
                }
            }
            return false;
        }

        /// <summary>
        /// Returns Toolbar by it's name if not found return 0
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public Toolbar toolbar_get(string name)
        {
            name = name.ToLower();
            foreach (Toolbar toolbar in toolbars)
            {
                if (toolbar.Name.ToLower() == name)
                {
                    return toolbar;
                }
            }
            return null;
        }

        public void font_StringParser(string fontstring)
        {
            string[] fontParser = fontstring.Split(';');

            float fontsize;
            try{
                fontsize=float.Parse(fontParser[1]);
            }catch{
                fontsize=font.Size;
            }
            if (fontsize > 600) { fontsize = font.Size; }
   
            font = new System.Drawing.Font(fontParser[0], fontsize);
        }
        /// <summary>
        /// Save the settings to the current config file
        /// </summary>
        public void save_settings()
        {
            string filename = Main.System_CONFIGFILE;
            XmlTextWriter xmlFile=null;
            try
            {
                xmlFile = new XmlTextWriter(filename, System.Text.Encoding.UTF8);

                xmlFile.Formatting = Formatting.Indented;

                xmlFile.WriteStartElement("NotepadX");

                xmlFile.WriteStartElement("Options");

                xmlFile.WriteStartElement("Location");
                xmlFile.WriteString(location[0].ToString() + ";" + location[1].ToString());
                xmlFile.WriteEndElement();

                
                xmlFile.WriteStartElement("Size");
                xmlFile.WriteString(size[0].ToString() + ";" + size[1].ToString());
                xmlFile.WriteEndElement();

                xmlFile.WriteStartElement("Lite");
                xmlFile.WriteString(LiteVersion.ToString());
                xmlFile.WriteEndElement();                

                xmlFile.WriteStartElement("Font");
                xmlFile.WriteString(font.Name + ";" + font.Size);
                xmlFile.WriteEndElement();

                xmlFile.WriteStartElement("Language");
                xmlFile.WriteString(language);
                xmlFile.WriteEndElement();

                xmlFile.WriteStartElement("Icons");
                xmlFile.WriteString(icons);
                xmlFile.WriteEndElement();

                xmlFile.WriteStartElement("Extension_Save");
                xmlFile.WriteString(extension_save);
                xmlFile.WriteEndElement();

                xmlFile.WriteStartElement("Extension_Open");
                xmlFile.WriteString(extension_open);
                xmlFile.WriteEndElement();

                xmlFile.WriteStartElement("Line_Numbers");
                xmlFile.WriteString(line_numbers.ToString());
                xmlFile.WriteEndElement();
                
                xmlFile.WriteStartElement("Status_Bar");
                xmlFile.WriteString(status_bar.ToString());
                xmlFile.WriteEndElement();

                xmlFile.WriteStartElement("Background_Color");
                if (BackgroundColor == null){
                    xmlFile.WriteString("default");
                }else{
                    xmlFile.WriteString(BackgroundColor);
                }
                xmlFile.WriteEndElement();

                xmlFile.WriteStartElement("Text_Color");
                if (TextColor == null) {
                    xmlFile.WriteString("default");
                }else{
                    xmlFile.WriteString(TextColor);
                }
                xmlFile.WriteEndElement();

                xmlFile.WriteStartElement("Default_Document_Type");
                xmlFile.WriteString(defaultDocumentType.ToString());
                xmlFile.WriteEndElement();

                xmlFile.WriteEndElement();

                xmlFile.WriteStartElement("Recent");
                foreach (RecentMenuItemX item in recent)
                {
                    if (!string.IsNullOrEmpty(item.path))
                    {
                        xmlFile.WriteStartElement("File");
                        xmlFile.WriteString(item.path);
                        xmlFile.WriteEndElement();
                    }
                }
                xmlFile.WriteEndElement();

                xmlFile.WriteStartElement("Favourites");
                foreach (RecentMenuItemX item in favourites)
                {
                    xmlFile.WriteStartElement("File");
                    xmlFile.WriteString(item.path.ToString());
                    xmlFile.WriteEndElement();
                }
                xmlFile.WriteEndElement();

                
                //foreach (Toolbar item in toolbars)
                //{
                //    xmlFile.WriteStartElement("Toolbar");
                //    xmlFile.WriteString(item.filename);
                //    xmlFile.WriteEndElement();
                //}
                xmlFile.WriteStartElement("Toolbars");
                Boolean[] Flags = new Boolean[toolbars.Count];
                for (int i = 0; i < toolbars.Count; i++) Flags[i] = true;
                for (int i = 0; i < toolbars.Count; i++)
                {
                    int min = 0;
                    while (!Flags[min])
                    {
                        min++;
                    }
                    for (int j = 1; j < toolbars.Count; j++)
                    {
                        if (Flags[j] && ((Toolbar)toolbars[j]).DisplayIndex < ((Toolbar)toolbars[min]).DisplayIndex)
                        {
                            min = j;
                        }
                    }
                    Flags[min] = false;
                    xmlFile.WriteStartElement("Toolbar");
                    xmlFile.WriteString(((Toolbar)toolbars[min]).filename);
                    xmlFile.WriteEndElement();
                }
                Flags = null;
                xmlFile.WriteEndElement();

                xmlFile.WriteStartElement("Plugins");
                for (int i = 0; i < Notepad_X.Plugin.Global.Plugins.AvailablePlugins.Count; i++)
                {
                    xmlFile.WriteStartElement("Plugin");
                    xmlFile.WriteString(System.IO.Path.GetFileName(Notepad_X.Plugin.Global.Plugins.AvailablePlugins.get(i)));
                    xmlFile.WriteEndElement();

                }
                xmlFile.WriteEndElement();

                xmlFile.WriteStartElement("Shortcuts");
                foreach (DictionaryEntry item in shortcuts)
                {   
                    xmlFile.WriteStartElement("Shortcut");
                    xmlFile.WriteAttributeString("name", ((shortcut)item.Value).item.Name);
                    xmlFile.WriteAttributeString("key", (((shortcut)item.Value).keyString).ToString());
                    xmlFile.WriteEndElement();
                }
                xmlFile.WriteEndElement();

                   xmlFile.WriteStartElement("PluginsSettings");
                   foreach (pluginSetting item in pluginsSettings) {
                       if (item.values.Count == 0) continue;
                       xmlFile.WriteStartElement("Plugin");
                       xmlFile.WriteAttributeString("name", item.name);
                       foreach ( System.Collections.Generic.KeyValuePair<string,string>  key  in item.values) {
                           xmlFile.WriteStartElement("Setting");
                           xmlFile.WriteAttributeString("name", key.Key);
                           xmlFile.WriteString(key.Value);
                           xmlFile.WriteEndElement();
                       }
                       xmlFile.WriteEndElement();
                   }
                   xmlFile.WriteEndElement();
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Error writing the settings file :" + ex.Message, "Error", System.Windows.Forms.MessageBoxButtons.AbortRetryIgnore, System.Windows.Forms.MessageBoxIcon.Error);
            }
            finally
            {
                xmlFile.Close();
            }
           

        }
        /// <summary>
        /// Loads the settings from the current config file
        /// </summary>
        public void load_settings()
        {
            string filename = Main.System_CONFIGFILE;

            if (System.IO.File.Exists(filename))
            {
                XmlDocument xmlFile = new XmlDocument();             
                xmlFile.Load(filename);

                XmlNodeList nodes = xmlFile.GetElementsByTagName("Options");

                if (nodes.Count == 1)
                {
                    string[] reader;
                    foreach (XmlNode node in nodes[0].ChildNodes)
                    {
                        switch (node.Name.ToLower())
                        {
                            case "location":
                                reader = node.InnerText.Split(';');
                                location[0] = int.Parse(reader[0]);
                                location[1] = int.Parse(reader[1]);
                                if (location[0] < 0) { location[0] = 0; }
                                if (location[1] < 0) { location[1] = 0; }
                                if (location[0] > System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width -50) { location[0] = 0; }
                                if (location[1] > System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height -50) { location[1] = 0; }
                                break;
                            case "size":
                                reader = node.InnerText.Split(';');
                                size[0] = int.Parse(reader[0]);
                                size[1] = int.Parse(reader[1]);
                                break;
                            case "lite":
                                Boolean.TryParse(node.InnerText,out LiteVersion);
                                break;
                            case "font":
                                font_StringParser(node.InnerText);
                                break;
                            case "language":
                                language = node.InnerText;
                                break;
                            case "icons":
                                if (!LiteVersion) { iconReader(node.InnerText); }
                                break;
                            case "extension_save":
                                extension_save = node.InnerText;
                                break;
                            case "extension_open":
                                extension_open = node.InnerText;
                                break;
                            case "line_numbers":
                                line_numbers = bool.Parse(node.InnerText);
                                break;
                            case "status_bar":
                                status_bar = bool.Parse(node.InnerText);
                                break;
                            case "background_color":
                                if (node.InnerText.ToLower() == "default"){
                                    BackgroundColor = null;
                                }else{
                                    BackgroundColor = node.InnerText;
                                }
                                break;
                            case "text_color":
                                if (node.InnerText.ToLower() == "default"){
                                    TextColor = null;
                                }else{
                                    TextColor = node.InnerText;
                                }
                                break;
                            case "default_document_type":
                                defaultDocumentType = int.Parse(node.InnerText);
                                break;
                        }
                    }
                }
                nodes = xmlFile.GetElementsByTagName("Recent");

                if (nodes.Count == 1)
                {
                    foreach (XmlNode node in nodes[0].ChildNodes)
                    {
                        if (System.IO.File.Exists(node.InnerText))
                        {
                            for(int i=0;i<recent.Length;i++){
                                if(recent[i].path==null){
                                    recent[i].changePath(node.InnerText);
                                    break;
                                }
                            }
                        }
                    }
                }
                nodes = xmlFile.GetElementsByTagName("Favourites");

                if (nodes.Count == 1 && !LiteVersion)
                {
                    foreach (XmlNode node in nodes[0].ChildNodes)
                    {
                        if (System.IO.File.Exists(node.InnerText))
                        {
                            favourite_add(node.InnerText);

                        }
                    }
                }
                nodes = xmlFile.GetElementsByTagName("Toolbars");

                if (nodes.Count == 1 && !LiteVersion)
                {
                    foreach (XmlNode node in nodes[0].ChildNodes)
                    {
                        toolbar_add(node.InnerText);
                    }
                }

                nodes = xmlFile.GetElementsByTagName("PluginsSettings");
                if (nodes.Count == 1 && !LiteVersion) {
                    foreach (XmlElement node in nodes[0].ChildNodes) {
                        pluginSetting newPluginSetting = new pluginSetting(node.GetAttribute("name"));
                        XmlNodeList subNodes = node.GetElementsByTagName("Setting");
                        if (subNodes.Count == 0) continue;
                        foreach (XmlElement subNode in subNodes) {
                            newPluginSetting.values.Add(new System.Collections.Generic.KeyValuePair<string, string>(subNode.GetAttribute("name"), subNode.InnerText));
                        }
                        pluginsSettings.Add(newPluginSetting);
                    }
                }

                nodes = xmlFile.GetElementsByTagName("Plugins");

                if (nodes.Count == 1 && !LiteVersion)
                {
                    foreach (XmlNode node in nodes[0].ChildNodes)
                    {
                        if (System.IO.File.Exists(Main.System_ROOT + "\\Plugins\\" +node.InnerText))
                        {
                            Notepad_X.Plugin.Global.Plugins.AddPlugin(Main.System_ROOT + "\\Plugins\\" + node.InnerText);
                         }

                    }
                }
                nodes = xmlFile.GetElementsByTagName("Shortcuts");
                if (nodes.Count == 1)
                {
                    foreach (XmlElement node in nodes[0].ChildNodes)
                    {
                        this.shortcut_add(node.GetAttribute("name"), node.GetAttribute("key"));
                    }
                }

            }
        }

        public static System.Drawing.Color ParseColor(String ColorString) {
            try {
                if (ColorString.StartsWith("color.")) {
                    System.Drawing.ColorConverter cV = new System.Drawing.ColorConverter();
                    return (System.Drawing.Color)cV.ConvertFrom(ColorString.Split('.')[1]);
                } else if (ColorString.Contains(".")) {
                    return System.Drawing.Color.FromArgb(int.Parse(ColorString.Split('.')[0]), int.Parse(ColorString.Split('.')[1]), int.Parse(ColorString.Split('.')[2]));
                }else{
                    return System.Drawing.SystemColors.WindowText;
                }                    
           } catch { return System.Drawing.Color.Empty; }
        }

        /// <summary>
        /// Reads an icon file and returns the properties as array (Name,Author,Version,Description,Link)
        /// </summary>
        /// <param name="path">Icon file path</param>
        public static string[] hashIconPack(string path)
        {
            string[] ret;
            try
            {
                XmlDocument xmlFile = new XmlDocument();
                xmlFile.Load(path);
                ret = new string[5];
                ret[0] = xmlFile.SelectSingleNode("NotepadX/Information/Name").InnerText;
                ret[1] = xmlFile.SelectSingleNode("NotepadX/Information/Author").InnerText;
                ret[2] = xmlFile.SelectSingleNode("NotepadX/Information/Version").InnerText;
                ret[3] = xmlFile.SelectSingleNode("NotepadX/Information/Description").InnerText;
                ret[4] = xmlFile.SelectSingleNode("NotepadX/Information/Link").InnerText;
            }
            catch
            {
            ret = null;
            }
            return ret;
        }
    }
    public class pluginSetting{
       public string name;
       public System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<string, string>> values;

       public pluginSetting(String _name) {
           name = _name;
           values = new System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<string, string>>();
       }
    }
}
